<template>
	
	<view>
		<view class="edgeInsetTop"></view>
		<view class="cu-form-group">
			<view class="title">姓名</view>
			<input type="text" placeholder="请输入真实姓名" v-model="name" style="text-align: right;"></input>
		</view>
		
		<view class="cu-form-group">
			<view class="title">身份证号码</view>
			<input type="text" placeholder="请输入真实身份证号码"  v-model="idNo" style="text-align: right;"></input>
		</view>
		
		<view class="real-btn wanl-bg-orange" @click="userauth()">
			<image src="/static/images/face.png" class="face"></image>
			<text>人脸识别</text>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			name: '',
			idNo: '',
		};
	},

	methods: {
		// 发起认证
		//https://ext.dcloud.net.cn/plugin?id=10378
		//https://blog.csdn.net/qq_40716795/article/details/136014333
		userauth() {
			var that = this;
			
			if (!this.name) {
				this.$wanlshop.msg('请输入真实姓名');
				return;
			}
			if (!this.idNo) {
				this.$wanlshop.msg('请输入真实身份证号码');
				return;
			}
			
			uni.request({
				url: '/user/userauth',
				data: {
					name: this.name,
					idcard_no:this.idNo,
				},
				success: res => {
					res = res.res
					console.log("user/userauth result", res);
					if (res.code === 1) {
						that.make(res.data);
					}
				}
			});
		},
		make(result){
			let that = this;
			
			const face = uni.requireNativePlugin('DC-WBFaceServiceV2');
			face.startWbFaceVerifyService({
			  userId: result.userId,
			  nonce : result.nonce,
			  sign : result.sign,
			  appId : result.appId,
			  orderNo : result.orderNo,
			  apiVersion : "1.0.0",
			  licence : "H8SgRuOonOYjW0Tx/zPcBkVYCNyAY936lNNLlw+QxotaTciBxPGqrLBtib/gNg1Uws0ihx9AobeP5OucOK2lJIo3GMLww+Z2ru/i+Qt0BlViiJpG37Zjn4uYZwqBZVZBezXKTiQNZBR/SmnatVxZpYlmUD+z6kKCkET77+/81C9W5A8/qeMMW4B4XCH8jlzZqdfjvWSStccaiWLA9LHrlK6sXIm1k/oy6jWOT9uEue6u01h2s+2KoxfaDauEhMbQl8lLjVUu6VO8QYfxBp7pKP2CmkQugaIeDp7WPp8vTVYj6uh4GvFrSo9jalI6Ux0bZ/W5LkjOic9ZGf0qEClJ/Q==",
			  compareType:"0",
			  faceId: result.faceId,
			  sdkConfig: {
			    //和iOS共有的配置参数
			    showSuccessPage: false, //是否展示成功页面,默认不展示
			    showFailurePage: false, //是否展示失败页面,默认不展示
			    recordVideo: false, //是否录制视频,默认不录制
			    checkVideo:false,//是否检查视频大小
			    playVoice: false, //是否播放语音提示，默认不播放
			    theme: '1', //sdk皮肤设置，0黑色，1白色
			    customerTipsLoc:'0',//自定义提示的位置，0在预览框下面，1在预览框上面
			    customerTipsInLive:'',//检测时的自定义提示语
			    customerTipsInUpload:'',//上传时的自定义提示语
			    customerLongTip:'',//自定义长提示语
			    //android独有的配置参数
			    isEnableLog: true, //是否打开刷脸native日志，请release版本关闭！！！
			    //iOS独有的配置参数
			    windowLevel: '1', //sdk中拉起人脸活体识别界面中使用UIWindow时的windowLevel配置
			    manualCookie: true ,//是否由SDK内部处理sdk网络请求的cookie
			    useWindowSecene: false,
			  }
			}, 
			result => {
			  console.log("【uni log】face SDK callback ================> result.");
			  console.log(result);
			  
	
			  //验证成功
			  if(result.res.success){
				  uni.request({
				  	url: '/user/userauthquery',
				  	data: {},
				  	success: res => {
				  		res = res.res
						console.log("user/userauthquery result", res);
								  
				  		if (res.code === 1) {
				  			that.$wanlshop.msg('实名认证成功');
							
							setTimeout(function (){
								uni.switchTab({
									url: '/pages/user',
								})
							}, 1000)
				  		}
				  	}
				  });
			  }
			  
			  // {
			  //     "scene": "wb_face_callback_verify_result",
			  //     "res": {
			  //         "sign": "CB89E6E037634C54124C69E6EB3D7783512275DF",
			  //         "similarity": "96.24",
			  //         "orderNo": "20240319173731NDQ3j4KmfMSvVLWPCe",
			  //         "success": true,
			  //         "liveRate": "99"
			  //     }
			  // }
			  
			  
			});
		}

	},

}	
</script>

<style>
.uni-input-placeholder{
	text-align: right !important;
}

.uni-input-input{
	text-align: right !important;
}

.uni-input-form, .uni-input-wrapper{
	text-align: right !important;
}
</style>


<style scoped>
.real-btn {
	width: 80%;
	height: 80rpx;
	border-radius: 30px;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 28rpx;
	position: absolute;
	bottom: 70rpx;
	left: 50%;
	transform: translate(-50%);
	color: white;
}

.face {
	margin-right: 10rpx;
	width: 40rpx;
	height: 40rpx;
}

.cu-form-group{
	background-color: #ffffff;
	border-radius: 20rpx;
	margin: 32rpx 38rpx 0px 38rpx;
	display: flex;
	align-items: center;
	justify-content: space-between;
}
</style>